{% extends "base.html" %}

{% load crispy_forms_tags i18n translations %}

{% block breadcrumbs %}
  <li class="breadcrumb-item">
    <a href="{% url 'manage' %}">{% translate "Manage" %}</a>
  </li>
  <li class="breadcrumb-item">
    <a href="{% url 'manage-ssh' %}">{% translate "SSH keys" %}</a>
  </li>
{% endblock breadcrumbs %}

{% block content %}

  {% include "snippets/ssh-key.html" with key_download=True %}

  {% if can_generate %}
    {% for ssh_key in missing_ssh_keys %}
      <form method="post">
        <div class="card">
          <div class="card-header">
            <h4 class="card-title">
              {% documentation_icon 'vcs' 'ssh-repos' right=True %}
              {% blocktranslate with key_type=ssh_key.name %}Generate {{ key_type }} SSH key{% endblocktranslate %}
            </h4>
          </div>
          <div class="card-body">
            <p>
              {% blocktranslate with key_type=ssh_key.name %}You don't seem to have existing {{ key_type }} SSH key, by pressing button below Weblate will generate one for you.{% endblocktranslate %}
            </p>
            {% csrf_token %}
            <input type="hidden" name="action" value="generate">
            <input type="hidden" name="type" value="{{ ssh_key.type }}">
          </div>
          <div class="card-footer">
            <input type="submit"
                   id="generate-ssh-button"
                   class="btn btn-primary"
                   value="{% blocktranslate with key_type=ssh_key.name %}Generate new {{ key_type }} SSH key{% endblocktranslate %}" />
          </div>
        </div>
      </form>
    {% endfor %}
  {% endif %}

  {% if host_keys %}
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">
          {% documentation_icon 'vcs' 'verify-ssh' right=True %}
          {% translate "Known host keys" %}
        </h4>
      </div>

      <table class="table table-striped">
        <thead>
          <tr>
            <th>{% translate "Hostname" %}</th>
            <th>{% translate "Key type" %}</th>
            <th>{% translate "Fingerprint" %}</th>
          </tr>
        </thead>
        <tbody>
          {% for key in host_keys %}
            <tr class="row{% cycle '1' '2' %}">
              <td>{{ key.0 }}</td>
              <td>{{ key.1 }}</td>
              <td>{{ key.2 }}</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  {% endif %}

  <form method="post" class="form-inline">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">
          {% documentation_icon 'vcs' 'verify-ssh' right=True %}
          {% translate "Add host key" %}
        </h4>
      </div>
      <div class="card-body">
        <p>
          {% translate "To access SSH hosts, its host key needs to be verified. You can get the host key by entering a domain name or IP for the host in the form below." %}
        </p>
        {% crispy add_form %}
        <input type="hidden" name="action" value="add-host" />
      </div>
      <div class="card-footer">
        <input type="submit"
               id="ssh-add-button"
               class="btn btn-primary"
               value="{% translate "Submit" %}" />
      </div>
    </div>
  </form>

{% endblock content %}
